package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BehaviorRecode;
import com.ruoyi.system.service.IBehaviorRecodeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 低碳行为记录管理Controller
 * 
 * @author 墨染
 * @date 2024-09-28
 */
@RestController
@RequestMapping("/system/behaviorRecode")
public class BehaviorRecodeController extends BaseController
{
    @Autowired
    private IBehaviorRecodeService behaviorRecodeService;

    /**
     * 查询低碳行为记录管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:behaviorRecode:list')")
    @GetMapping("/list")
    public TableDataInfo list(BehaviorRecode behaviorRecode)
    {
        startPage();
        List<BehaviorRecode> list = behaviorRecodeService.selectBehaviorRecodeList(behaviorRecode);
        return getDataTable(list);
    }

    /**
     * 导出低碳行为记录管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:behaviorRecode:export')")
    @Log(title = "低碳行为记录管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BehaviorRecode behaviorRecode)
    {
        List<BehaviorRecode> list = behaviorRecodeService.selectBehaviorRecodeList(behaviorRecode);
        ExcelUtil<BehaviorRecode> util = new ExcelUtil<BehaviorRecode>(BehaviorRecode.class);
        util.exportExcel(response, list, "低碳行为记录管理数据");
    }

    /**
     * 获取低碳行为记录管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:behaviorRecode:query')")
    @GetMapping(value = "/{behaviorId}")
    public AjaxResult getInfo(@PathVariable("behaviorId") Long behaviorId)
    {
        return success(behaviorRecodeService.selectBehaviorRecodeByBehaviorId(behaviorId));
    }

    /**
     * 新增低碳行为记录管理
     */
    @PreAuthorize("@ss.hasPermi('system:behaviorRecode:add')")
    @Log(title = "低碳行为记录管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BehaviorRecode behaviorRecode)
    {
        return toAjax(behaviorRecodeService.insertBehaviorRecode(behaviorRecode));
    }

    /**
     * 修改低碳行为记录管理
     */
    @PreAuthorize("@ss.hasPermi('system:behaviorRecode:edit')")
    @Log(title = "低碳行为记录管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BehaviorRecode behaviorRecode)
    {
        return toAjax(behaviorRecodeService.updateBehaviorRecode(behaviorRecode));
    }

    /**
     * 删除低碳行为记录管理
     */
    @PreAuthorize("@ss.hasPermi('system:behaviorRecode:remove')")
    @Log(title = "低碳行为记录管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{behaviorIds}")
    public AjaxResult remove(@PathVariable Long[] behaviorIds)
    {
        return toAjax(behaviorRecodeService.deleteBehaviorRecodeByBehaviorIds(behaviorIds));
    }
}
